#include "FixtureManager.h"

FixtureManager::FixtureManager(QObject *parent)
    : QObject(parent)
{
    // 初始化所有气缸状态为未知
    for (int i = 1; i <= 16; ++i) {
        m_fixtureStates[i] = Unknown;
    }
}

FixtureManager::FixtureState FixtureManager::getFixtureState(int fixtureNumber) const
{
    return m_fixtureStates.value(fixtureNumber, Unknown);
}

void FixtureManager::setFixtureState(int fixtureNumber, FixtureState state)
{
    if (m_fixtureStates.value(fixtureNumber) != state) {
        m_fixtureStates[fixtureNumber] = state;
        emit fixtureStateChanged(fixtureNumber, state);
    }
}

void FixtureManager::resetAllStates()
{
    for (int i = 1; i <= 16; ++i) {
        m_fixtureStates[i] = Unknown;
    }
}

QString FixtureManager::getStateText(FixtureState state) const
{
    switch (state) {
    case Clamped: return "夹紧";
    case Released: return "松开";
    case Unknown: return "未知";
    default: return "未知";
    }
}

QString FixtureManager::getCurrentStateText(int fixtureNumber) const
{
    return getStateText(getFixtureState(fixtureNumber));
}
